<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
    <title>登录页</title>
</head>

<body>
<form id="signInForm">
    <div><label>用户名<input type="text" name="name"></label></div>
    <div><label>密码<input type="password" name="password"></label></div>
    <div><button>登陆</button></div>
</form>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script>
    //监听submit事件
    const $signInForm=$('#signInForm')
    $signInForm.on('submit',(e)=>{
        e.preventDefault() //阻止默认事件的发生
        const name =$signInForm.find('input[name=name]').val()
        const password = $signInForm.find('input[name=password]').val()
         //发送POST请求
    $.ajax({
        method:'POST',
        contentType:'text/jason;charset=UTF_8',
        url:'/sign_in',
        data:JSON.stringify({name,password})
    }).then(()=>{
        alert('登陆成功啦')
        location.href='/home.html'
    },()=>{})
    })
   
</script>
</body>

</html>